#include<p24fj128ga006.h>
#include<p24fj128ga006.h>
#include <libpic30.h>
#include "monitor.h"

void status(unsigned char *info,unsigned char info_len)
{
   in1_buffer[0] = 0x02; //start of data 
   in1_buffer[1] = 0x01; //from device
   in1_buffer[2] = 0x00; //to PC
   in1_buffer[3] = 0x03; //reply
   in1_buffer[4] = 0x01; //length
   in1_buffer[5] = 0x09; //DBA wested bandwidth                        
   in1_buffer[6] = 0x03; //end of data	    

   send_URX1();//send to PC
   
}


void time_stamp(void)
{
    unsigned char *temp_store;
    int i;

    in1_buffer[0] = 0x02; //start of data 
    in1_buffer[1] = 0x01; //from device
    in1_buffer[2] = 0x00; //to PC
    in1_buffer[3] = 0x03; //reply
              
    in1_buffer[5] = 0x04; //get counter32 value

    temp_store = changeLong2Byte(timer_counter32); 
    for(i=0;i<4;i++)
    {
       in1_buffer[i+6] = temp_store[i]; //load timer value
    }
    in1_buffer[4] = i+1; //length
    in1_buffer[i+6] = 0x03; //end of data

    send_URX1();//send to PC

}


void capture_delay(unsigned char capture)
{
    int i;
    unsigned char *temp_store;
    long int delta = 0;


    if(capture == 0x01)
    {
        start_time = timer_counter32;
    }
    else if(capture == 0x02)
    {
       stop_time = timer_counter32;
    
       in1_buffer[0] = 0x02; //start of data 
       in1_buffer[1] = 0x01; //from device
       in1_buffer[2] = 0x00; //to PC
       in1_buffer[3] = 0x03; //reply
              
       in1_buffer[5] = 0x08; //delay

       
       delta = stop_time - start_time;

       temp_store = changeLong2Byte(delta); 
       for(i=0;i<4;i++)
       {
           in1_buffer[i+6] = temp_store[i]; //load timer value
       }
       in1_buffer[4] = i+1; //length
       in1_buffer[i+6] = 0x03; //end of data

       send_URX1();//send to PC
    }  

}
